Skip to content

PHOENIX-7795 : Tenant TTL using Tenant Views on Multi-Tenant Table#2400

Open
palashc wants to merge 13 commits intoapache:masterfrom
palashc:tenant_ttl
Open

PHOENIX-7795 : Tenant TTL using Tenant Views on Multi-Tenant Table#2400
palashc wants to merge 13 commits intoapache:masterfrom
palashc:tenant_ttl

Conversation

@palashc
Copy link
Copy Markdown
Contributor

@palashc palashc commented Apr 6, 2026

Summary

Enable per-tenant TTL on multi-tenant base tables by letting a tenant create a view (with or without a WHERE clause) and set TTL on it. Read masking and compaction use the existing View TTL infrastructure.

Changes

  • WhereOptimizer.getRowKeyMatcher: compute ROW_KEY_MATCHER from the connection's tenant-id when a tenant view is created without a WHERE clause, so it participates in the compaction RowKeyMatcher trie. Wraps ScanUtil.getTenantIdBytes in try/catch to avoid breaking creation when the tenant-id type doesn't match the schema.
  • CreateTableCompiler.compile: always invoke getRowKeyMatcher for UPDATABLE views (no longer gated on where != null).

New validation (ViewUtil.validateTenantViewWithoutWhereTTLCoexistence)

On a multi-tenant base table, among a given tenant's views without a WHERE clause, we allow either:

  • (a) any number of no-WHERE views without TTL, or
  • (b) exactly one no-WHERE view with TTL.
    Multiple no-WHERE TTL views share the same ROW_KEY_MATCHER (tenant-id bytes) and would conflict in the compaction RowKeyMatcher trie. The check rejects such operations with TENANT_VIEW_WITHOUT_WHERE_TTL_CONFLICT. Views with WHERE clauses are out of scope for this check (their prefix-conflict potential is a pre-existing concern tracked separately).
    The helper lives in ViewUtil and is invoked from:
  • CREATE VIEW (CreateTableCompiler) when creating a no-WHERE view on a multi-tenant base table.
  • ALTER VIEW SET TTL (MetaDataClient.evaluateStmtProperties) when the view being altered is a no-WHERE tenant view on a multi-tenant base table; the view itself is excluded from the sibling check.
    Gracefully skips when CHILD_LINK is unavailable (namespace mapping edge cases) or in connectionless mode (unit tests).

Tests (TenantTTLIT)

  • testReadMaskingWithDifferentTenantTTLs
  • testCompactionWithDifferentTenantTTLs — INTEGER non-tenant PK
  • testThreeTenantsDifferentTTLsCHAR(3) + BIGINT PK columns
  • testCompactionWithSplitRegions — pre-split base table
  • testCompactionWithSaltedMultiTenantTable
  • testCompactionWithTenantTableIndex — with secondary index on the base table
  • testSameViewNameAcrossDifferentTenants
  • testTenantTTLWithUpdatableViewRestrictionEnabled
  • testTenantTTLViewCoexistenceRules — 9 cases exercising every CREATE-path branch (no-WHERE non-TTL, no-WHERE TTL, mixed, different tenants, newly-allowed WHERE-scoped creations)
  • testAlterTTLOnTenantViewWithSiblingIsRejected — ALTER-path rejection for no-WHERE views
  • testAlterTTLOnWhereScopedTenantViewIsAllowed — ALTER-path allowed for WHERE-scoped views
  • testAlterTenantViewToAddTTL — ALTER TTL masking/compaction end-to-end
  • testChildViewsOfTenantTTLViewInheritTTL — child views inherit parent tenant view's TTL

@palashc palashc marked this pull request as draft April 6, 2026 22:32
@palashc palashc requested a review from jpisaac April 6, 2026 22:32
@palashc palashc marked this pull request as ready for review April 7, 2026 20:01
@palashc palashc changed the title PHOENIX-7795 : Tenant TTL using Global Views PHOENIX-7795 : Tenant TTL using Tenant Views on Multi-Tenant Table Apr 8, 2026
Copy link
Copy Markdown
Contributor

@jpisaac jpisaac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, Few test suggestions

@palashc palashc requested a review from jpisaac April 21, 2026 18:31
Palash Chauhan added 2 commits April 21, 2026 14:23
@palashc palashc marked this pull request as draft April 23, 2026 06:36
@palashc palashc marked this pull request as ready for review April 23, 2026 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants